package com.example.perpetualcalendar.ui.fragment.calendar;

import androidx.annotation.NonNull;
import androidx.lifecycle.Observer;

import com.example.perpetualcalendar.R;
import com.example.perpetualcalendar.base.BaseFragment;
import com.example.perpetualcalendar.databinding.FragmentHomeBinding;
import com.example.perpetualcalendar.domain.entity.Calendar;


/**
 * @author langhua
 */
public class CalendarFragment extends BaseFragment<CalendarViewModel, FragmentHomeBinding> {

    @Override
    protected void initView() {
        mViewModel.getDto().observe(getViewLifecycleOwner(), new Observer<Calendar.ResultDTO.DataDTO>() {
            @Override
            public void onChanged(Calendar.ResultDTO.DataDTO dataDTO) {
                if(dataDTO.getHoliday()!=null){
                    viewBinding.textHoliday.setText(dataDTO.getHoliday());
                }else {
                    viewBinding.textHoliday.setText("");
                }
                viewBinding.textLunar.setText(dataDTO.getLunar());
                viewBinding.textYear.setText(dataDTO.getLunarYear()+"·"+dataDTO.getAnimalsYear());
                viewBinding.textAvoid.setText(dataDTO.getAvoid());
                viewBinding.textSuit.setText(dataDTO.getSuit());
            }
        });
        viewBinding.calendarView.setOnDateChangeListener((view, year, month, dayOfMonth) -> {
            mViewModel.calendar(year+"-"+(month+1)+"-"+dayOfMonth);
        });
    }

    @NonNull
    @Override
    protected Class<CalendarViewModel> setViewModel() {
        return CalendarViewModel.class;
    }

    @NonNull
    @Override
    protected int setLayout() {
        return R.layout.fragment_home;
    }
}